//
//  MapUtils.swift
//  amap
//
//  Created by James Karl on 2020/7/5.
//

import Foundation
import MAMapKit

class MapUtils {
    
    func handle(_ call: FlutterMethodCall, with result: @escaping FlutterResult) {
        switch call.method {
        case "distance":
            distance(call: call, result: result)
        default:
            result(FlutterMethodNotImplemented)
        }
    }
    
    func distance(call: FlutterMethodCall, result: @escaping FlutterResult) {
        let args = call.arguments as! NSDictionary
        let from = LatLngData(dict: args["from"] as! NSDictionary)
        let to = LatLngData(dict: args["to"] as! NSDictionary)
        let p1 = MAMapPointForCoordinate(from.toMapPoint())
        let p2 = MAMapPointForCoordinate(to.toMapPoint())
        result(MAMetersBetweenMapPoints(p1, p2))
    }
}
